package com.slz.crm.pojo.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.slz.crm.pojo.ao.Privacy;
import com.slz.crm.pojo.entity.CustomerContactEntity;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 客户联系人VO
 */
@Data
public class CustomerContactVO implements Privacy {
    private Long id;
    private Long companyId;
    private String companyName;
    private String name;
    private String position;
    private String phone;
    private String mobile;
    private String email;
    private int gender;
    private String remark;
    private Long createId;
    private int isDeleted;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime updateTime;

    @Override
    public Boolean email() {
        this.email = "***";
        return true;
    }

    @Override
    public Boolean mobile() {
        this.mobile = "***";
        return true;
    }

    @Override
    public Boolean phone() {
        this.phone = "***";
        return true;
    }

    @Override
    public Boolean position() {
        this.position = "***";
        return true;
    }

    /**
     * 从Entity创建VO，需要传入公司名称
     * @param entity 客户联系人实体
     * @param companyName 公司名称
     * @return CustomerContactVO
     */
    public static CustomerContactVO fromEntity(CustomerContactEntity entity, String companyName) {
        if (entity == null) {
            return null;
        }

        CustomerContactVO vo = new CustomerContactVO();
        vo.setId(entity.getId());
        vo.setCompanyId(entity.getCompanyId());
        vo.setCompanyName(companyName);
        vo.setName(entity.getName());
        vo.setPosition(entity.getPosition());
        vo.setPhone(entity.getPhone());
        vo.setMobile(entity.getMobile());
        vo.setEmail(entity.getEmail());
        vo.setGender(entity.getGender());
        vo.setRemark(entity.getRemark());
        vo.setCreateId(entity.getCreatorId());
        vo.setIsDeleted(entity.getIsDeleted() ? 1 : 0);
        vo.setCreateTime(entity.getCreateTime());
        vo.setUpdateTime(entity.getUpdateTime());

        return vo;
    }



}
